package com.swpu.project.model.entity;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.swpu.project.constant.XlxsConstant;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.lang.reflect.Field;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class XlxsEntity {






    /*
   *
   *  原生还是次生
   *
   * */

   private String type;

    /**
     * 原生id
     */

    private String id;

    /**
     * 岩屑样本名
     */
    private String name;

    /**
     * 区块名
     */
    private String blockName;

    /**
     * 油井名
     */
    private String oilwellName;

    /**
     * 井深低值
     */
    private String oilwellLow;

    /**
     * 井深高值
     */
    private String oilwellDeep;

    /**
     * 层位
     */
    private String position;

    /**
     * 岩性
     */
    private String lithology;

    /**
     * 钻井液名
     */
    private String fluidName;

    /**
     * 备注
     */
    private String Notes;
       /*重金属
       * */
      private InformClassify heavyMetal=new InformClassify(XlxsConstant.INFORM_HEAVY);
  /*
  *  非重金属
  *
  * */
     private InformClassify nonHeavyMetal=new InformClassify(XlxsConstant.INFORM_NON_HEAVY);
    /*  矿物
    * */
     private InformClassify  mineral=new InformClassify(XlxsConstant.INFORM_MINERAL);
public void setAll( List<InformClassify> informClassifies)
{          int index=getInformOrder();
          Class<XlxsEntity> xlxsEntityClass = XlxsEntity.class;
          Field[] declaredFields = xlxsEntityClass.getDeclaredFields();
        for(int i=0;i<getInformNum();i++,index++)
      {    Field field=declaredFields[index];
            field.setAccessible(true);
          try {
           InformClassify informClassify =(InformClassify) field.get(this);
            for(int z=0;z<informClassifies.size();z++)
            {  if(informClassifies.get(z).getName().equals(informClassify.getName()))
              {
                  InformClassify informClassify1   = BeanUtil.copyProperties(informClassifies.get(z),InformClassify.class);

                  field.set(this,informClassify1);

              }


            }
          } catch (IllegalAccessException e) {
              e.printStackTrace();
          }




      }



}
public void initInformData(String informName,List<Inform>  informs)
{   switch (informName) {
    case XlxsConstant.INFORM_HEAVY:
   this.heavyMetal.initData(informs);

     break;

    case XlxsConstant.INFORM_NON_HEAVY:
        this.nonHeavyMetal.initData(informs);
        break;

    case XlxsConstant.INFORM_MINERAL:
        this.mineral.initData(informs);
        break;


}




}







public static final Integer getInformNum()
{
    Class<XlxsEntity> xlxsEntityClass = XlxsEntity.class;
    Field[] declaredFields = xlxsEntityClass.getDeclaredFields();
    int num=0;
    for (int i = 0; i < declaredFields.length; i++) {
        Field declaredField = declaredFields[i];
        declaredField.setAccessible(true);
        if(declaredField.getType()==InformClassify.class)
             num++;
    }

    return num;
}

public static final Integer getInformOrder()
{
    Field[] declaredFields = XlxsEntity.class.getDeclaredFields();
    return   declaredFields.length-getInformNum();


}





}
